package cac.fenjian.resource.oracle.rest;

import cac.fenjian.resource.WmsDeliverPlan.dto.WmsDeliverPlanDTO;
import com.alibaba.fastjson.JSON;
import com.cac.dme.adapter.rest.msg.PageParameter;
import com.cac.dme.adapter.rest.msg.QueryReqBean;
import com.cac.dme.adapter.rest.msg.QueryRespBean;
import com.cac.dme.adapter.rest.msg.ResponseMsg;
import com.cac.dme.adapter.utils.ContextCommonHolder;
import com.cac.dme.common.utils.JsonHelper;
import com.fasterxml.jackson.core.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import static com.cac.dme.adapter.utils.BusinessUtil.getSortExpColumnName;
import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

@RestController
@RequestMapping("/oralceConnect")
public class TestOraConnect {

    //零件接收条码查询
    @PostMapping("/testConnect")
    public void searchByBarcodeAM(@RequestBody Map map){
        ResponseMsg<QueryRespBean<WmsDeliverPlanDTO>> responseMsg = new ResponseMsg<>();
        //获取条码
        String username = (String) map.get("username");
        String password = (String) map.get("password");
        String ip = (String) map.get("ip");
        String orcl = (String) map.get("orclname");

        String driver = "oracle.jdbc.driver.OracleDriver";
       String url = "jdbc:oracle:thin:@"+ip+"/"+orcl;
        String sql = "insert into users(username,password) values (?,?)";

        try {

            Class.forName(driver);        //oracle.jdbc.driver.OracleDriver();

            Connection conn = null;
            try {
                System.out.println(""+url+"     "+username+"    "+password);
                conn = DriverManager.getConnection(url, username,password);


                if(conn==null){
                    System.out.println("数据库连接失败");
                }
                else{
                    System.out.println("数据库连接成功");
                }
                conn.close();

            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
